package chapter07.h7_2;

import java.io.PrintWriter;

public class HTMLBuilder extends Builder {
    private String filename;
    private PrintWriter printWriter;

    @Override
    protected void buildTitle(String title) {
        filename = title + ".html";
        try {
            printWriter = new PrintWriter(filename);

        }catch (Exception e){
            e.printStackTrace();
        }
        printWriter.println("<html><head><title>" + title + "</title></head><body>");
        printWriter.println("<hl>" + title + "</hl>" );
    }

    @Override
    protected void buildString(String str) {
        printWriter.println("<p>" + str + "</p>");
    }

    @Override
    protected void buildItems(String[] items) {
        printWriter.println("<ul>");
        for (int i = 0; i < items.length; i ++){
            printWriter.println("<li>" + items[i] + "</li>");
        }
        printWriter.println("</ul");
    }

    @Override
    protected void buildDone() {
        printWriter.println("<body></html>");
        printWriter.close();
    }

    public String getResult(){
        return filename;
    }
}
